/**
 * 
 */
package org.mspring.mlog.utils;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Gao Youbo
 * @since 2012-11-22
 * @Description
 * @TODO 附件
 */
public class AttachmentUtils {

    public static final String ATTACHMENT_DIRECTORY = "/attachment";

    /**
     * 文件保存路径
     * 
     * @param mf
     * @return
     */
    public static String getUploadPath(MultipartFile mf) {
        return getUploadPath(FilenameUtils.getExtension(mf.getOriginalFilename()));
    }

    /**
     * 文件保存路径
     * 
     * @param extension
     * @return
     */
    public static String getUploadPath(String extension) {
        StringBuilder sb = new StringBuilder();
        sb.append(UploadUtils.getUploadDirectory(ATTACHMENT_DIRECTORY));
        sb.append(UploadUtils.getUniqueFilename());
        sb.append(".").append(extension);
        return sb.toString();
    }

}
